package com.jsaber.blogSystem.service.impl;

import com.jsaber.blogSystem.pojo.Article;
import com.jsaber.blogSystem.repository.ArticleRepository;
import com.jsaber.blogSystem.service.ArticleService;
import com.jsaber.blogSystem.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * @author zhouzijia
 * @version 1.0
 * @description
 * @date 2020/12/13 11:04
 */

@Service
public class ArticleServiceImpl implements ArticleService {

    // 固定每页显示文章数量 3
    public static int PAGE_OF_SIZE = 3;

    @Autowired
    private ArticleRepository articleRepository;

    @Override
    public Page<Article> articleList(Integer page){

        int currentPage = PageUtil.getPage(page);

        return articleRepository.findAll(PageRequest.of(currentPage, PAGE_OF_SIZE));

    }

}
